<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px">
      <el-form-item label="到货单号" prop="arrivedCode">
        <el-input
          v-model="queryParams.arrivedCode"
          placeholder="请输入采购到货单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="供应商" prop="vendorName">
        <el-input
          v-model="queryParams.vendorName"
          placeholder="请输入供应商名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单据状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择单据状态" clearable>
          <el-option label="已确认" value="CONFIRMED"/>
          <el-option label="草稿" value="PREPARE"/>
        </el-select>
      </el-form-item>
      <el-form-item label="是否退货回冲" prop="isReturn">
        <el-select v-model="queryParams.isReturn" placeholder="是否退货回冲" clearable>
          <el-option label="是" value="Y"/>
          <el-option label="否" value="N"/>
        </el-select>
      </el-form-item>
      <el-form-item label="订单编号" prop="orderCode">
        <el-input
          v-model="queryParams.orderCode"
          placeholder="请输入采购订单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="计划编号" prop="planNumber">
        <el-input
          v-model="queryParams.planNumber"
          placeholder="请输入采购计划编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="采购员" prop="buyer">
        <el-input
          v-model="queryParams.buyer"
          placeholder="请输入采购员姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料编号" prop="itemCode">
        <el-input
          v-model="queryParams.itemCode"
          placeholder="请输入物料编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料名称" prop="itemName">
        <el-input
          v-model="queryParams.itemName"
          placeholder="请输入物料名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否需要质检" prop="iqcCheck">
        <el-select v-model="queryParams.iqcCheck" placeholder="是否需要质检" clearable>
          <el-option label="是" value="Y"/>
          <el-option label="否" value="N"/>
        </el-select>
      </el-form-item>
      <el-form-item label="质检单编号" prop="iqcCode">
        <el-input
          v-model="queryParams.iqcCode"
          placeholder="请输入来料质检单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="质检结果" prop="checkResult">
        <el-select v-model="queryParams.checkResult" placeholder="请选择质检结果" clearable>
          <el-option
            v-for="dict in dict.type.mes_qc_result"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="客户名称" prop="clientName">
        <el-input
          v-model="queryParams.clientName"
          placeholder="请输入客户名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['cg:arrivedDetailTable:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="tableList" >
      <el-table-column label="到货单号" align="center" prop="arrivedCode">
        <template slot-scope="scope">
          <el-span v-if="scope.row.isReturn == 'N'">{{scope.row.arrivedCode}}</el-span>
          <el-span v-if="scope.row.isReturn == 'Y'" style="color: red">{{scope.row.arrivedCode}}</el-span>
        </template>
      </el-table-column>
      <el-table-column label="供应商" align="center" prop="vendorName"/>
      <el-table-column label="联系人" align="center" prop="contact"/>
      <el-table-column label="电话" align="center" prop="contactTel"/>
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_order_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="是否退货回冲" align="center" prop="isReturn">
        <template slot-scope="scope">
          <el-span v-if="scope.row.isReturn == 'N'">否</el-span>
          <el-span v-if="scope.row.isReturn == 'Y'">是</el-span>
        </template>
      </el-table-column>
      <el-table-column label="物料名称" align="center" prop="itemName"/>
      <el-table-column label="物料编号" align="center" prop="itemCode"/>
      <el-table-column label="规格型号" align="center" prop="specification"/>
      <el-table-column label="单位" align="center" prop="unitOfMeasure"/>
      <el-table-column label="物料分类" align="center" prop="itemTypeName"/>
      <el-table-column label="订单编号" align="center" prop="orderCode"/>
      <el-table-column label="计划编号" align="center" prop="planNumber"/>
      <el-table-column label="采购员" align="center" prop="buyer"/>
      <el-table-column label="到货数量" align="center" prop="arrivedQuantity"/>
      <el-table-column label="是否需要质检" align="center" prop="iqcCheck">
        <template slot-scope="scope">
          <el-span v-if="scope.row.iqcCheck == 'N'">否</el-span>
          <el-span v-if="scope.row.iqcCheck == 'Y'">是</el-span>
        </template>
      </el-table-column>
      <el-table-column label="质检单号" align="center" prop="iqcCode"/>
      <el-table-column label="质检结果" align="center" prop="checkResult">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_qc_result" :value="scope.row.checkResult"/>
        </template>
      </el-table-column>
      <el-table-column label="客户编码" align="center" prop="clientCode"/>
      <el-table-column label="客户名称" align="center" prop="clientName"/>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {listTable} from "@/api/mes/cg/arrivedDetailTable";

export default {
  name: "ArrivedDetailTable",
  dicts: ['mes_order_status','mes_qc_result'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 采购到货单明细表格数据
      tableList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        arrivedCode: null,
        vendorName: null,
        status: null,
        isReturn: null,
        orderCode: null,
        planNumber: null,
        buyer: null,
        itemCode: null,
        itemName: null,
        iqcCheck: null,
        iqcCode: null,
        checkResult: null,
        clientName: null,
      },

    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询采购到货单明细列表 */
    getList() {
      this.loading = true;
      listTable(this.queryParams).then(response => {
        this.tableList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('cg/arrivedDetailTable/export', {
        ...this.queryParams
      }, `采购到货明细_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
